const {
    Mysql
} = require('../tools');
module.exports = async ctx => {
    let { uid, vid, from, pageNum, pageSize } = ctx.query;
    if (!uid || typeof (Number(uid)) != 'number') {
        ctx.state.data = {
            code: '002',
            msg: '参数缺失'
        }
        return;
    }
    else {
        if (from == 'status') {
            if (!vid) {
                ctx.state.data = {
                    code: '002',
                    msg: '参数缺失'
                }
                return
            }
            let sql = `SELECT status FROM collectVideo WHERE uid = ${Number(uid)} AND vid = ${Number(vid)}`;
            try {
                let res = await Mysql(sql);
                if (res.length) {
                    ctx.state.data = {
                        code: '001',
                        data: res[0].status
                    }
                }
                else {
                    ctx.state.data = {
                        code: '001',
                        data: 0
                    }
                }

            } catch (error) {
                ctx.state.data = {
                    code: '002',
                    msg: '内部错误'
                }
            }
        }
        else {
            if (!pageNum || !pageSize) {
                ctx.state.data = {
                    code: '002',
                    msg: '内部错误'
                }
                return;
            }
            let sql = `SELECT collectVideo.id,video.vid,video.title,video.coverImg,video.isNew,video.isVip,video.type,video.sort FROM collectVideo RIGHT JOIN video ON video.vid=collectVideo.vid WHERE uid=${uid} AND collectVideo.status=1 LIMIT ${(pageNum - 1) * pageSize},${pageSize}`;
            try {
                let res = await Mysql(sql);
                ctx.state.data = {
                    code: '001',
                    data: res
                }
            } catch (error) {
                ctx.state.data = {
                    code: '002',
                    msg: '内部错误'
                }
            }
        }
    }
}